﻿using Client.Todo.Common;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Todo.ViewModels
{
    public class MessageViewModel : BindableBase, IDialogHostAware
    {
        /// <summary>
        /// 添加待办
        /// </summary>
        public MessageViewModel()
        {
            OkCmd = new DelegateCommand(ExceuteOk);
            CancelCmd = new DelegateCommand(ExceuteCancel);
            IgnoreCmd = new DelegateCommand(ExceuteIgnore);
        }

        void ExceuteOk()
        {
            DialogParameters param = new DialogParameters();
            DialogHost.Close(DialogHostNmae, new DialogResult(ButtonResult.OK, param));
        }
        void ExceuteCancel()
        {
            DialogParameters param = new DialogParameters();
            DialogHost.Close(DialogHostNmae,new DialogResult(ButtonResult.Cancel,param));
        }
        void ExceuteIgnore()
        {

        }

        #region 标题

        /// <summary>
        /// 标题
        /// </summary>
        private string _title;

        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        #endregion 标题 

        #region 内容

        /// <summary>
        /// 内容
        /// </summary>
        private string _content;

        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        {
            get { return _content; }
            set { SetProperty(ref _content, value); }
        }

        #endregion 内容 

        public string DialogHostNmae { get; set; }
        public DelegateCommand OkCmd { get; set; }
        public DelegateCommand IgnoreCmd { get; set; }
        public DelegateCommand CancelCmd { get; set; }

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            if (parameters.ContainsKey(nameof(Title)))
            {
                Title = parameters.GetValue<string>(nameof(Title));
            }

            if (parameters.ContainsKey(nameof(Content)))
            {
                Content = parameters.GetValue<string>(nameof(Content));
            }

        }

    }
}
